package com.eatme.web.sys.workflow.activiti.event.message;

import org.activiti.api.process.runtime.ProcessRuntime;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.Execution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MessageEvent {
    private static final Logger LOG = LoggerFactory.getLogger(MessageEvent.class);
    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private ProcessRuntime processRuntime;
    public void signalStart(String messageName,String processDefinitionId) {
        Execution exec = runtimeService.createExecutionQuery()
                .messageEventSubscriptionName(messageName)
                .processInstanceId(processDefinitionId)
                .singleResult();
        runtimeService.messageEventReceived(messageName,exec.getId());
//        runtimeService.startProcessInstanceByMessage(messageName);
//
//        ProcessInstance pi = processRuntime.start(StartMessagePayloadBuilder
//                        .start(messageName)
//                .build()
//                );
        LOG.info("通过消息流转任务节点");
    }
}
